package com.itheima.rxdemo;

/**
 * Created by TUTU on 2016-11-18.
 * 显示当前天气的公告牌  (观察者,展示者)
 */
public class CurrentConditionsDisplay implements Observer,DispalyElement {
    private WeatherData1 mWeatherData1; //天气的数据. 相当于被观察者.

    private float temperature;//温度
    private float humidity;//湿度
    private float pressure;//气压

    //在构造函数中创建被观察者的引用. 并把这个观察者加入到队列里
    public CurrentConditionsDisplay(WeatherData1 weatherData1) {
        mWeatherData1 = weatherData1;
        mWeatherData1.registerObserver(this);
    }

    /**
     * 用来展示数据用
     */
    @Override
    public void display() {
        System.out.println("当前温度为：" + this.temperature + "℃");
        System.out.println("当前湿度为：" + this.humidity);
        System.out.println("当前气压为：" + this.pressure);
    }

    /**
     * 用来更新
     */
    @Override
    public void update() {
        this.temperature = this.mWeatherData1.getTemperature();
        this.humidity = this.mWeatherData1.getHumidity();
        this.pressure = this.mWeatherData1.getPressure();
        display();
    }
}
